package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;

import org.springframework.core.convert.converter.Converter;
import org.springframework.format.Formatter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.Locale;

@Component
public class StringToItemTypeConverter implements Converter<String, ItemType>/*, Formatter<Object>*/ {
    @Override
    public ItemType convert(String s) {
        for(ItemType itemType : ItemType.values()) {
            if(itemType.getCode().equals(Integer.valueOf(s))) {
                return itemType;
            }
        }
        throw new IllegalArgumentException("非法");
    }


//
//    @Override
//    public Object parse(String text, Locale locale) throws ParseException {
//        return null;
//    }
//
//    @Override
//    public String print(Object object, Locale locale) {
//        return "";
//    }
}
